package 反射3;
/*
@Date:2025/3/17
*/

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class TestUserReflection {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        final Class<User> userClass = User.class;
        final User o = userClass.newInstance();
        System.out.println("o = " + o);
        //反射动态获取构造器
        final Constructor<User> constructor = userClass.getConstructor(String.class);
        final User aaa = constructor.newInstance("aaa");
        System.out.println("aaa = " + aaa);
        final Constructor<User> constructor1 = userClass.getConstructor(int.class, String.class);
        final User lisi = constructor1.newInstance(4, "里斯");
        System.out.println("lisi = " + lisi);


    }
}
